// import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_foodybite/Global.dart';
// import 'package:flutterchallenge/constant.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_foodybite/Constants.dart';

class ThemeModel with ChangeNotifier {
  /// 深色模式 0: 关闭 1: 开启 2: 随系统
  int _darkMode = 0;

  int get darkMode => _darkMode;

  void changeMode(int darkMode) async {
    debugPrint("changeMode _darkMode=$_darkMode, darkMode=$darkMode");
    if (_darkMode != darkMode) {
      _darkMode = darkMode;
      notifyListeners();
      _saveMode(darkMode);
    }
  }

  void changeMode1() async {
    debugPrint("changeMode1 _darkMode=$_darkMode, darkMode=$darkMode");
    if (_darkMode == 0) changeMode(1);
    else if (_darkMode == 1) changeMode(2);
    else if (_darkMode == 2) changeMode(0);
  }

  _saveMode(int mode) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    int mode = prefs.getInt(THEME_MODE) ?? 0;
    print('saveMode: $mode ');
    await prefs.setInt(THEME_MODE, mode);
  }

  _saveLanguage(int mode) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    int mode = prefs.getInt(LANGUAGE_MODE) ?? 0;
    print('saveLanguage: $mode ');
    await prefs.setInt(LANGUAGE_MODE, mode);
  }
}